package com.thundersoft.pickcolor.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import com.thundersoft.pickcolor.R;
import com.thundersoft.pickcolor.bean.Color;
import com.thundersoft.pickcolor.viewholder.TypeAbstractViewHolder;
import com.thundersoft.pickcolor.viewholder.TypeOneViewHolder;
import com.thundersoft.pickcolor.viewholder.TypeTwoViewHolder;
import com.thundersoft.pickcolor.viewholder.TypeZeroViewHolder;

import java.util.ArrayList;
import java.util.List;

public class ColorAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<Color> mColorList = new ArrayList<>();;
    private LayoutInflater mLayoutInflater;

    public ColorAdapter(Context context) {
        mLayoutInflater = LayoutInflater.from(context);
    }

    public void clearList(){
        mColorList.clear();
    }

    public void addList(List<Color> list){
        mColorList.addAll(list);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        switch (viewType){
            case Color.TYPE_ONE:
                return new TypeOneViewHolder(mLayoutInflater.inflate(R.layout.color_item_one,
                        viewGroup,false));
            case Color.TYPE_TWO:
                return new TypeTwoViewHolder(mLayoutInflater.inflate(R.layout.color_item_two,
                        viewGroup,false));
            case Color.TYPE_ZERO:
                return new TypeZeroViewHolder(mLayoutInflater.inflate(R.layout.color_item_zero,
                        viewGroup,false));
        }
        return null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
        ((TypeAbstractViewHolder)viewHolder).bindHolder(mColorList.get(position));
    }
    @Override
    public int getItemCount() {
        return mColorList.size();
    }

    @Override
    public int getItemViewType(int position) {
        return mColorList.get(position).type;
    }
}